/*--------------------------------------------------------------------------
 *  Copyright 2011 Taro L. Saito
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *--------------------------------------------------------------------------*/
//--------------------------------------
// XerialJ
//
// AkkaActor.java
// Since: 2011/07/12 16:32:37
//
// $URL$
// $Author$
//--------------------------------------
package org.xerial.silk.weaver.cloud;

import static akka.actor.Actors.*;

import org.xerial.util.log.Logger;

import akka.actor.ActorRef;
import akka.actor.UntypedActor;

public class AkkaActor
{
    private static Logger _logger = Logger.getLogger(AkkaActor.class);

    // server code
    public static class HelloWorldActor extends UntypedActor
    {
        private static Logger _logger = Logger.getLogger(AkkaActor.HelloWorldActor.class);

        @Override
        public void onReceive(Object msg) {

            getContext().replySafe(msg + " World");
            _logger.info("resieved: " + msg);
        }
    }

    public static void sample() {
        remote().start("localhost", 9999).register("hello-service", actorOf(HelloWorldActor.class));

        // client code
        ActorRef actor = remote().actorFor("hello-service", "localhost", 9999);
        Object res = actor.sendRequestReply("Hello");
        _logger.info("finished: " + res);
    }
}
